import request from '@/utils/request.ts';
import type {
  PermissionListResData,
  PermissionList
} from './permission-type.ts';
import type { ResponseData } from '../type.ts';

enum API {
  GET_PERMISSION_LIST = '/admin/acl/permission',
  SAVE_PERMISSION = '/admin/acl/permission/save',
  UPDATE_PERMISSION = '/admin/acl/permission/update',
  DELETE_PERMISSION = '/admin/acl/permission/remove'
}

// 获取权限菜单列表
export const reqGetPermissionList = () =>
  request.get<any, PermissionListResData>(API.GET_PERMISSION_LIST);

// 提交权限菜单
export const reqSaveOrUpdatePermission = (data: PermissionList) => {
  const url = data.id ? API.UPDATE_PERMISSION : API.SAVE_PERMISSION;
  const method = data.id ? 'put' : 'post';
  return request[method]<any, ResponseData>(url, data);
};

// 删除权限菜单
export const reqDeletePermission = (id: number) =>
  request.delete<any, ResponseData>(`${API.DELETE_PERMISSION}/${id}`);
